home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / tc_tsr10.zip / TSRPRTSC.C < prev   
Text File  |  1991-06-18  |  8KB  |  173 lines

  1. /*--------------------------------------------------------------------------*
  2.  | TsrPrtSc.C                                                               |
  3.  |   contains main, interrupt handling, and DOS interface routines          |
  4.  |  TsrPrtSc.c is supplied as is with no warranty, expressed or implied.    |
  5.  |  It is not copyrighted, either.                                          |
  6.  *--------------------------------------------------------------------------*/
  7. /*--------------------------------------------------------------------------*
  8.  | Author:                                                                  |
  9.  | Sherif El-Kassas        .       :.                                       |
  10.  | EB dept           \_____o__/ __________                                  |
  11.  | Eindhoven U of Tec       .. /                                            |
  12.  | The Netherlands            /             Email: elkassas@eb.ele.tue.nl   |
  13.  *--------------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------------*
  16.  | The author shall not be liable to the user for any direct, indirect      |
  17.  | or consequential loss arising from the use of, or inability to use,      |
  18.  | any program or file howsoever caused.  No warranty is given that the     |
  19.  | programs will work under all circumstances.                              |
  20.  *--------------------------------------------------------------------------*/
  21.  
  22.  
  23. #include <dos.h>
  24. #include "prtsc.h"
  25.  
  26. /*------------------------------------------------------------------------*
  27.  |                           GLOBAL VARIABLES                             |
  28.  *------------------------------------------------------------------------*/
  29.  
  30. void interrupt (* old_intr_0x09)();      /* pointer to old interrupt 0x9  */
  31. void interrupt (* old_intr_0x28)();      /* pointer to old interrupt 0x28 */
  32.  
  33. unsigned _heaplen = 1;                   /* set minimum heap size         */
  34.  
  35. unsigned c_ss, c_sp;        /* c_ss, c_sp are used to save PRTSC'S stack  */
  36. unsigned save_ss, save_sp;  /* save_ss and save_sp are used to save the   */
  37.                             /* active stack                               */
  38.  
  39. byte active = FALSE;  /* program active flag (to prevent recursion)       */
  40. byte wanted = FALSE;  /* wanted is set to TRUE if the Hot key was pressed */
  41.                       /* but the program could not be activated           */
  42.  
  43. byte far * dos_active;                        /* pointer to DOS busy flag */
  44. byte far * shift_byte = (byte far *) 0x00400017L; /* pointer to keyboard  */
  45.                                                   /* status byte          */
  46.  
  47. /*------------------------------------------------------------------------*
  48.  |                       Keyboard interrupt handler                       |
  49.  *------------------------------------------------------------------------*/
  50.  
  51. void kbd_reset(void){    /* Reset Keyboard and programable interrupt      */
  52.                          /* controller (PIC)                              */
  53.      register char x;
  54.      x = inp(0x61);
  55.      outp(0x61, (x | 0x80));
  56.      outp(0x61, x);
  57.      cli();
  58.      outp(0x20, 0x20);
  59.      sti();
  60. }/* kbd_reset */
  61.  
  62.  
  63. void interrupt intr_0x09(){  /* interrupt 9 handler (whenever a key is    */
  64.                              /* pressed control arrives hear)             */
  65.      register char x;
  66.  
  67.      sti();
  68.      x = inp(0x60);                   /* read keyboard data port          */
  69.      if ( ( !active )        &&       /* if the program is not active and */
  70.           ( x == SCAN_CODE ) &&       /* x == hot key scan code and     */
  71.           ( ((*shift_byte) & ALT) != 0) /* the ALT key is pressed       */
  72.      )
  73.      {
  74.        active = TRUE;        /* set active to prevent recursion           */
  75.        kbd_reset();          /* reset keyboard controller and PIC         */
  76.        if (!(*dos_active)){  /* if DOS is not active then do main task    */
  77.          wanted = FALSE;
  78.          do_main_task();
  79.        }
  80.        else wanted = TRUE;   /* else set wanted flag to be processed via  */
  81.                              /* interrupt 0x28                            */
  82.        active = FALSE;
  83.      }
  84.      else (* old_intr_0x09)(); /* call old interrupt 9 handler            */
  85.  
  86. } /* intr_0x09 */
  87.  
  88.  
  89. /*------------------------------------------------------------------------*
  90.  |                       Interrupt 0x28 handler                           |
  91.  *------------------------------------------------------------------------*/
  92. void interrupt intr_0x28(){
  93.  
  94.      (* old_intr_0x28)(); /* call old interrupt 0x28(to give other memory */
  95.                           /* resident programs a chance to pop-up !)      */
  96.  
  97.      if (wanted){         /* if the wanted flag is set then do main task  */
  98.        wanted = FALSE;
  99.        active = TRUE;
  100.        sti();
  101.        do_main_task();
  102.        cli();
  103.        active = FALSE;
  104.      }
  105.  
  106. } /* intr_0x28 */
  107.  
  108.  
  109. /*------------------------------------------------------------------------*
  110.  |                       do_main_task                                     |
  111.  *------------------------------------------------------------------------*/
  112. void do_main_task(void){
  113.  
  114.      cli();                        /* disable interrupts                  */
  115.      save_ss = _SS; save_sp = _SP; /* save the current stack              */
  116.      _SS = c_ss; _SP = c_sp;       /* restore PrtSc's stack               */
  117.      sti();                        /* enable interrupts                   */
  118.      main_task();                  /* call the print screen routines      */
  119.      cli();                        /* disable interrupts                  */
  120.      _SS = save_ss; _SP = save_sp; /* restore stack                       */
  121.      sti();                        /* enable interrupts                   */
  122.  
  123. } /* do_main_task() */
  124.  
  125.  
  126. /*------------------------------------------------------------------------*
  127.  |                       get_dos_flag                                     |
  128.  *------------------------------------------------------------------------*/
  129.  
  130. byte far * get_dos_flag(void){   /* get a pointer to DOS busy flag        */
  131.      union  REGS  reg;
  132.      struct SREGS s_reg;
  133.  
  134.      reg.x.ax = 0x3400;                /* function 0x34 get DOS busy flag */
  135.      intdosx(®, ®, &s_reg);      /* call DOS (interrupt 0x21)       */
  136.      return( MK_FP(s_reg.es, reg.x.bx) ); /* return far pointer ES:BX     */
  137.  
  138. }/* get_dos_flag() */
  139.  
  140.  
  141. /*------------------------------------------------------------------------*
  142.  |                         program_size                                   |
  143.  *------------------------------------------------------------------------*/
  144.  
  145. unsigned program_size(void){   /* return the size of the current memory   */
  146.                            /* control block (in paragraphs)               */
  147.  
  148.     return(* ((unsigned far *) (MK_FP(_psp-1, 3))) );
  149.  
  150. }/* program_size() */
  151.  
  152.  
  153. /*------------------------------------------------------------------------*
  154.  |                         main function                                  |
  155.  *------------------------------------------------------------------------*/
  156. main(){
  157.  
  158.   initialize_video();             /* get video mode assume page 0         */
  159.  
  160.   c_ss = _SS; c_sp = _SP;         /* save PrtSC's stack                   */
  161.  
  162.   dos_active = get_dos_flag();    /* get a pointer to DOS busy flag       */
  163.  
  164.   old_intr_0x28 = getvect(0x28);  /* save old interrupt 0x28 vector       */
  165.   setvect( 0x28, intr_0x28 ); /* set interrupt 0x28 vector to 'intr_0x28' */
  166.  
  167.   old_intr_0x09 = getvect(0x09);  /* save old interrupt 0x09 vector       */
  168.   setvect( 0x09, intr_0x09 ); /* set interrupt 0x09 vector to 'intr_0x09' */
  169.  
  170.   keep(0, program_size());    /* terminate and stay resident              */
  171.  
  172. } /* main() */
  173.